#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    void sortColors(vector<int>& nums)
    {
        int left = -1, right = nums.size(), cur = 0;
        while (cur < right)
        {
            if (nums[cur] == 0)
            {
                swap(nums[++left], nums[cur++]);
            }
            else if (nums[cur] == 1)
            {
                cur++;
            }
            else
            {
                swap(nums[cur], nums[--right]);
            }
        }
    }
};